//
//  BulidNewPhoneVm.swift
//  Pods
//
//  Created by eme on 2017/4/6.
//
//

import UIKit
import RxSwift
import ModelProtocol

class BulidNewPhoneVm{
    
    let backMessage = PublishSubject<Bool>()
    
    let buildPhone = PublishSubject<String>()
    
    let error = PublishSubject<MikerError>()
    
    var type = ""
    var code = ""
    
    let disposeBag = DisposeBag()
    
    init(){
        
        let request = buildPhone.map{ phone in
            return MineApi.buildNewPhone(phone: phone, type: self.type, code: self.code)
            }.shareReplay(1)
        
        let response = request.emeRequestApiForRegJson().shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            switch result{
            case.success(_):
                
                self.backMessage.onNext(true)
                
            case .failure(let error):
                
                self.error.onNext(error)
                
            }
        }).addDisposableTo(disposeBag)
        
    }
    
    
}
